<form class="layui-form seller-form"  action="" >
    <div class="layui-form-item" style="margin-bottom:0;">
        <div class="layui-inline">
            <label class="layui-form-label">售后单号：</label>
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="aftersales_id" lay-verify="title" placeholder="请输入售后单号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">订单号：</label>
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="order_id" lay-verify="title" placeholder="请输入订单号" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label" style="width:120px;">用户手机号码：</label>
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="mobile" lay-verify="title" placeholder="请输入手机号码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">售后类型：</label>
            <div class="layui-input-inline seller-inline-3" >
                <select name="type" lay-verify="">
                    <option value=""></option>
                    <option value="1">只退款</option>
                    <option value="2">退款退货</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">状态：</label>
            <div class="layui-input-inline seller-inline-3" >
                <select name="status" lay-verify="">
                    <option value=""></option>
                    <option value="1">未审核</option>
                    <option value="2">审核通过</option>
                    <option value="3">审核拒绝</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i class="iconfont icon-chaxun"></i>筛选</button>
        </div>
    </div>
</form>

<div class="table-body">
    <table id="billAftersales" lay-filter="test"></table>
</div>

<script>
    layui.use(['form', 'layedit', 'laydate','table'], function(){
        layui.table.render({
            elem: '#billAftersales',
            height: 'full-330',
            cellMinWidth: '80',
            page: 'true',
            limit:'{:config('jshop.page_limit')}',
            url: "{:url('billAftersales/index')}?_ajax=1",
            id:'billAftersales',
            cols: [[
                {field:'aftersales_id', width:140, sort: true,title:'售后单号'},
                {field:'order_id', width:140, sort: true,title:'订单号'},
                {field:'status_name', width:100,title:'状态'},
                {field:'type', width:100,title:'售后类型'},
                {field:'user_id', width:150,minWidth: 50,title:'用户'},
                {field:'refund',width:100,title:'退款金额'},
                {field:'reason',title:'原因'},
                {field:'ctime',width:170,title:'申请时间'},
                {field: 'operating', title: '操作', width:120, align: 'center',templet:function(data){
                    var html = '';
                    if(data.status == 1){
                        html += '<a  class="layui-btn layui-btn-xs option-audit" data-id="' + data.aftersales_id + '">操作</a>';
                    }
                    html += '<a  class="layui-btn layui-btn-xs option-view layui-btn-primary" data-id="' + data.aftersales_id + '">明细</a>';
                    return html;
                }},
            ]]
        });
        layui.form.on('submit(*)', function(data){
            layui.table.reload('billAftersales', {
                where: data.field
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    //审核操作
    $(document).on('click','.option-audit',function(){
        $.ajax({
            type:'get',
            url: "{:url('billAftersales/audit')}",
            data:'aftersales_id='+$(this).attr('data-id'),
            success:function(e){
                if(e.status){
                    window.box = layer.open({
                        type: 1,
                        content: e.data,
                        area: ['800px', '650px'],
                        title:'售后单审核',
                        btn: ['确认','取消'],
                        yes: function(index, layero){
                            $.ajax({
                                type:'post',
                                url: "{:url('billAftersales/audit')}",
                                data: $('#aftersales_form').serialize(),
                                success:function(res){
                                    if(res.status){
                                        layer.msg('保存成功');
                                        window.setTimeout("window.location.reload();",500);     //如果想做的更好就关掉弹出框，然后表格重新加载即可
                                    }else{
                                        layer.msg(res.msg);
                                    }
                                }
                            });
                        }
                    });
                }else{
                    layer.msg(e.msg);
                }

            }
        });
    });
        //查看操作
        $(document).on('click','.option-view',function(){
            $.ajax({
                type:'get',
                url: "{:url('billAftersales/view')}",
                data:'aftersales_id='+$(this).attr('data-id'),
                success:function(e){
                    if(e.status){
                        window.box = layer.open({
                            type: 1,
                            content: e.data,
                            area: ['600px', '600px'],
                            title:'售后单查看'
                        });
                    }else{
                        layer.msg(e.msg);
                    }

                }
            });
        });
    });
</script>
